/**
 * @created June 7, 2004
 * 
 * @modified March 7, 2007
 * @author jprieur
 */
package kernel;

import java.util.*;

public class DataBaseStation extends DataType 
{

    transient private String _name;
    
    transient private double _coordX;
    public final static double COORD_X_MIN = 0.0;
    public final static double COORD_X_DEF = 0.0;
    public double COORD_X_MAX;
    
    transient private double _coordY;
    public final static double COORD_Y_MIN = 0.0;
    public final static double COORD_Y_DEF = 0.0;
    public double COORD_Y_MAX;
    
    // former name for this attribute : reachMaxLength
    private double _maxReachRadius;
    public final static double MAX_REACH_RADIUS_DEF = 100;
    public final static double MAX_REACH_RADIUS_MIN = 0;
    
    private double _carrierRate;
    public final static double CARRIER_RATE_DEF = 2.0;
    public final static double CARRIER_RATE_MIN = 1.0;

    transient private Vector _wishedEmission;
    private Vector _probes;

    //frequency range
    private float _fmin;
    public final static float FMIN_DEF = 0;
    public final static float FMIN_MIN = 0;
    public final static float FMIN_MAX = 100000;

    private float _fmax;
    public final static float FMAX_DEF = 10000;
    public final static float FMAX_MIN = 0;
    public final static float FMAX_MAX = 100000;

    
    /**
     * Constructor
     * @param name name of the base station
     * @param x
     * @param y
     * @param maxReachRadius maximum radius within objects are reachable
     * @param carrierRate interference rate
     * @param wishedEmissions vector containing the wished emissions
     * @param probes vector containing the probes
     * @param fmin minimum frequency
     * @param fmax maximum frequency	 
     */
    public DataBaseStation(String name,
			   double x,
			   double y,
			   double maxReachRadius,
			   double carrierRate,
			   Vector wishedEmission, 
			   Vector probes,
			   float fmin,
			   float fmax) 
    {
	setName(name);
	setCoordX(x);
	setCoordY(y);
	setMaxReachRadius(maxReachRadius);
	setCarrierRate(carrierRate);
	setWishedEmission(wishedEmission);
	setProbes(probes);
	setFmin(fmin);
	setFmax(fmax);
    }

    /**
     * Constructor filling fields with default values
     */
    public DataBaseStation()
    {
	setName("");
	setCoordX(COORD_X_DEF);
	setCoordY(COORD_Y_DEF);
	setMaxReachRadius(MAX_REACH_RADIUS_DEF);
	setCarrierRate(CARRIER_RATE_DEF);
	setWishedEmission(new Vector());
	setProbes(new Vector());
	setFmin(FMIN_DEF);
	setFmax(FMAX_DEF);
    }

    public boolean setName(String name)
    {
	_name = name;
	return true;
    }

    public String getName()
    {
	return _name;
    }

    public boolean setCoordX(double x)
    {
	boolean done = false;
	COORD_X_MAX = Simulator.getSimulator().getEnvironment().getSpace().getWidth();
	if(checkBounds(COORD_X_MIN,COORD_X_MAX,x)){
	    _coordX = x;
	    done = true;
	}else{
	    _coordX = COORD_X_DEF;
	}
	return done;
    }
    
    public double getCoordX()
    {
	return _coordX;
    }

    public boolean setCoordY(double y)
    {
	boolean done = false;
	COORD_Y_MAX = Simulator.getSimulator().getEnvironment().getSpace().getHeight();
	if(checkBounds(COORD_Y_MIN,COORD_Y_MAX,y)){
	    _coordY = y;
	    done = true;
	}else{
	    _coordY = COORD_Y_DEF;
	}
	return done;
    }
    
    public double getCoordY()
    {
	return _coordY;
    }
    public boolean setMaxReachRadius(double maxReachRadius)
    {
	boolean done = false;
	if(checkBounds(MAX_REACH_RADIUS_MIN,UNDEFINED, maxReachRadius)){
	    _maxReachRadius = maxReachRadius;
	    done = true;
	}else{
	    _maxReachRadius = MAX_REACH_RADIUS_DEF;
	}
	return done;
    }

    public double getMaxReachRadius()
    {
	return _maxReachRadius;
    }

    public boolean setCarrierRate(double carrierRate)
    {
	boolean done = false;
	if(checkBounds(CARRIER_RATE_MIN,UNDEFINED, carrierRate)){
	    _carrierRate = carrierRate;
	    done = true;
	}else{
	    _carrierRate = CARRIER_RATE_DEF;
	}
	return done;
    }

    public double getCarrierRate()
    {
	return _carrierRate;
    }
   
    public boolean setWishedEmission(Vector wishedEmission)
    {
	_wishedEmission = wishedEmission;
	return true;
    }

    public Vector getWishedEmission()
    {
	return _wishedEmission;
    }

    public boolean setProbes(Vector probes)
    {
	_probes = probes;
	return true;
    }

    public Vector getProbes()
    {
	return _probes;
    }
	
    
    public float getFmin()
    {
	return _fmin;
    }
    
    public boolean setFmin(float fmin)
    {
	boolean done = false;
	if(checkBounds(FMIN_MIN,FMIN_MAX,fmin)){
	    _fmin = fmin;
	    done =true;
	}else{
	    _fmin = FMIN_DEF;
	    done = false;
	}
	return done;
    }
   
    public float getFmax()
    {
	return _fmax;
    }
    
    public boolean setFmax(float fmax)
    {
	boolean done = false;
	if(checkBounds(FMAX_MIN,FMAX_MAX,fmax)){
	    _fmax = fmax;
	    done =true;
	}else{
	    _fmax = FMAX_DEF;
	    done = false;
	}
	return done;
    }
    
    
    public String toString()
    {
	String s = "Base Station : name = " + _name + 
	    ";\n maxReachRadius = " + _maxReachRadius 
	    + ";\n carrierRate = " + _carrierRate 
	    + "; \n wishedEmission = ";
	for(int i = 0;i<_wishedEmission.size();i++){
	    s = s + _wishedEmission.get(i);
	}
	return s;
    }
    
	
	
}

